package com.lvs.zmwz.controller.admin;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lvs.zmwz.entity.SysRole;
import com.lvs.zmwz.entity.req.SysRoleReq;
import com.lvs.zmwz.entity.serach.SysRoleSearch;
import com.lvs.zmwz.service.ISysRoleService;
import com.lvs.zmwz.util.QPage;
import com.lvs.zmwz.util.ResultView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

@Validated
@RestController
@RequestMapping("/api/admin/role")
public class SysRoleController {

    @Autowired
    private ISysRoleService iHjRoleService;

    /**
     * 角色列表
     * @return
     */
    //@SaCheckPermission("role:list")
    @GetMapping("/list")
    public ResultView list(QPage qPage, SysRoleSearch hjRoleSearch) {
        IPage<SysRole> hjRoleList=this.iHjRoleService.getListAll(qPage,hjRoleSearch);
        return ResultView.ok(hjRoleList);
    }

    /**
     * 获取角色列表不分页
     * @return
     */
    @GetMapping("/getRoleListAll")
    public ResultView getRoleListAll() {
        return ResultView.ok(this.iHjRoleService.getListAll());
    }


    /**
     * 新增角色
     * @return
     */
    //@SaCheckPermission("role:add")
    @PostMapping("/addRole")
    public ResultView addRole(@Validated SysRoleReq hjRoleReq) {
        return this.iHjRoleService.addRole(hjRoleReq);
    }


    /**
     * 根据角色ID获取当前数据
     * @return
     */
    //@SaCheckPermission("role:get")
    @GetMapping("/getRoleId")
    public ResultView getRoleId(@NotNull(message = "角色ID不能为空") String roleId) {
        return this.iHjRoleService.getRoleId(roleId);
    }

    /**
     * 修改角色
     * @return
     */
    //@SaCheckPermission("role:update")
    @PostMapping("/updateRole")
    public ResultView updateRole(@Validated SysRoleReq hjRoleReq) {
        return this.iHjRoleService.updateRole(hjRoleReq);
    }

    /**
     * 删除角色
     * @return
     */
    //@SaCheckPermission("role:delete")
    @PostMapping("/deleteRole")
    public ResultView deleteRole(@NotNull(message = "角色ID不能为空") String roleId) {
        return this.iHjRoleService.deleteRole(roleId);
    }

    /**
     * 批量删除角色
     * @return
     */
    //@SaCheckPermission("role:batch")
    @PostMapping("/batchDeleteRole")
    public ResultView batchDeleteRole(@NotNull(message = "角色ID不能为空") String[] roleId) {
        return this.iHjRoleService.batchDeleteRole(roleId);
    }

    /**
     * 角色菜单列表
     * @return
     */
    @GetMapping("/roleMenuList")
    public ResultView roleMenuList(String roleId) {
        return this.iHjRoleService.roleMenuList(roleId);
    }




}
